<?php

class bus{
	
	// Class Constructor
	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function getBus(){
		
		$query = "Select * from bus";
		$rows = $this->db->getRows($query);
		
		return $rows;
	}

	public function get_data(){
		$query = "select idadmin, username, fullname, email from admin 
			where username='".$_COOKIE['c_usr']."'";

		$rows = $this->db->getRows($query);

		return $rows[0];	
	}
	public function hapusBus($data){
		
		$query ="DELETE FROM bus WHERE no_bus='".@$data."'";

		$rows = $this->db->getRows($query);

		header('Location: bus.php');
	}

	public function editBus($data){
		
		$query ="SELECT * FROM bus WHERE no_bus='".@$data."'";
		$rows = $this->db->getRows($query);

		return array_shift($rows);
		}
	public function Tambahbus($data){
		
		$query ="INSERT INTO `jadwal` (`no_bus`, `no_polisi`, `nama_mesin`, `nama_body`, `no_mesin`, `no_rangaka`, `kode_kelas`, `keterangan`) VALUES ('".@$data[0]."', ".@$data[1].", ".@$data[2].", '".@$data[3]."','".@$data[4]."','".@$data[5]."','".@$data[6]."','".@$data[7]."','".@$data[8]."')";

		$this->db->putRows($query);

		header('Location: bus.php');
	}

	public function PostEdit($data){
		
		$query ="UPDATE bus SET no_polisi=".$data[0].", nama_mesin='".$data[1]."', nama_body='".$data[2]."', no_mesin='".$data[3]."', no_rangka='".$data[4]."', kode_kelas='".$data[5]."', keterangan='".$data[6]."' WHERE no_bus='".$data[7]."'";

		$this->db->putRows($query);
	}

}